<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>hello vue</title>
    <script src="https://unpkg.com/vue@latest"></script>
</head>
<body>
    <div id="root"></div>
</body>
<script>
    Vue.createApp({
        data() {
            return {
                inputValue: '', //v-model="inputValue"实现输入框中的内容与data数据双向绑定
                list: []
            }
        },
        methods: {
            handleAddItem() { //vue的思想：面向数据编程
                this.list.push(this.inputValue.length==0 ? "空" : this.inputValue) //添加此时输入框中的内容
                this.inputValue = "" //清空输入框的内容
            }
        },
        //v-bind可以使标签中的属性与data绑定
        template: `
            <div>
                <input v-model="inputValue" />
                <input v-bind:value="inputValue" />
                <p>你输入的内容是{{inputValue}}</p>
                <button v-on:click="handleAddItem">增加</button>
                <ul>
                    <li v-for="(item,index) of list">第{{index}}个是{{item}}</li>
                </ul>
            </div>
        `
    }).mount('#root');
</script>
</html>